<!--<link rel="stylesheet" href="http://localhost/nusato/pribadi/themes/srabon/css/jquery-ui-1.8.16.custom.css"></link>-->
<!--<script src="<?php print $url?>js/jquery.ui.core.js"></script>-->
<script src="<?php print $url?>js/jquery.ui.datepicker.js"></script>
<script src="<?php print $url?>js/jquery.ui.autocomplete.js"></script>
<script src="<?php print $url?>js/jquery.price_format.1.8.min.js"></script>
<div id="main-content">
  <div class="container-fluid">
    <div class="row-fluid">
			<div class="span12">
				<div class="nonboxy-widget">
					<div class="widget-head">
						<h5><i class="black-icons blocks_images"></i><?php print $title;?></h5>
					</div>
					<div class="widget-content">
						<div class="widget-box">
              <?php print $this->form_eksternal->form_open("", 'class=" form-horizontal well" id="formoutlet"', 
                      array("id_detail" => $detail[0]->id_mrp_inventory_purchase))?>
								<fieldset>
									<div class="control-group">
										<label class="control-label">Title</label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_input('title', $detail[0]->title, "", $lock)?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Department</label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_dropdown('id_hrm_department', $department, array($detail[0]->id_hrm_department), "id='department'", $lock)?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Date</label>
										<div class="controls">
                      <?php
                      print $this->form_eksternal->form_date("tanggal", $detail[0]->tanggal, "tanggal", "", "", $lock)?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">PIC</label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_input('pic', $detail[0]->pic, "", $lock)?>
										</div>
									</div>
									<div class="control-group">
										<label class="control-label">Note</label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_textarea('note', $detail[0]->note, "", $lock)?>
										</div>
									</div>
                  <div class="control-group">
										<label class="control-label"><?php print lang("document")?></label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_upload('document', "", 'class="span4"', $lock)?>
                      <?php
                      if($detail[0]->file){
                        print "<br /><a href='".base_url()."/files/revdipa/{$detail[0]->document}'>{$detail[0]->document}</a>";
                      }
                      ?>
										</div>
									</div>
                  <div class="control-group">
										<label class="control-label">Status</label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_dropdown('status', array(1 => "Submitted", 2 => "Accepted", 3 => "Rejected", 4 => "Received"), array($detail[0]->status), "", $lock)?>
										</div>
									</div>
                  <div class="control-group">
										<label class="control-label">Supplier</label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_dropdown('id_mrp_supplier', $supplier, array($detail[0]->id_mrp_supplier), "", $lock)?>
										</div>
									</div>
                  <div class="control-group">
										<label class="control-label">No Transaksi</label>
										<div class="controls">
                      <?php print $this->form_eksternal->form_input('notransaksi', $detail[0]->notransaksi, "", $lock)?>
										</div>
									</div>
                  <div class="control-group">
										<?php
                    print $this->form_eksternal->form_addrow_tr(
                            array(lang("mrp_inventory"), lang("note"), lang("qty"), lang("price"), lang("discount"), lang("total")), 
                            $isi, 
                            site_url("mrp/asset/add-items-for-purchase"), 
                            "items", 
                            "id_items", 
                            "nomor_flag", 
                            $tr, 
                            "width='100%'", $lock, $lock, true, $tambah = array())
                    ?>
									</div>
                  <div class="control-group">
                    <?php print $this->form_eksternal->form_input('param', count($isi), 'id="nomor_flag" style="display: none;"')?>
                  </div>
								</fieldset>
								<div class="form-actions">
                  <?php
                  if($lock !== false){
                    print "<button class='btn btn-primary' type='submit'>".lang("save")."</button>";
                  }
                  if($detail[0]->status == 2){
                    print $this->form_eksternal->form_hidden("status", 4);
                    print "<button class='btn btn-primary' type='submit'>".lang("received")."</button>";
                  }
                  ?>
									<a href="<?php print site_url("mrp/asset/purchase")?>" class="btn"><?php print lang("cancel")?></a>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
  </div>
</div>
<script>
  function get_dot(asli, koma){
    asli = asli.toFixed(0);
    asli = asli.toString();
    var asli_temp = asli.split(".");
    var string = asli_temp[0];
    var string_hasil = "";
    
    var tanda = 0;
    var kl = string.length % 3;
    if(kl == 0)
      kl = 3;
    for(i = 0 ; i < string.length ; i++){
      if(tanda == 3 || i == kl){
        string_hasil = string_hasil + ".";
        tanda = 0;
        kl = 0;
      }
      string_hasil = string_hasil + string[i];
      tanda++;
    }
//    if(koma == true){
      if(!asli_temp[1])
        asli_temp[1] = '';
      
      return string_hasil;
//    }
//    else
//      return string_hasil;
  }
  function kill_dot(string){
    var string_hasil = "";
    for(i = 0 ; i < string.length ; i++){
      if(string[i] != "."){
        if(string[i] == ",")
          string_hasil = string_hasil + ".";
        else
          string_hasil = string_hasil + string[i];
      }
    }
    return string_hasil;
  }
  
  function add_row_tambahan(table,url,act,param){
    var no = parseInt($('#'+param).val());
    $('#'+param).val(no+1);
    $.post(url,{no:$('#'+param).val(),action:act},function(data){
        $(data).clone(true).insertBefore("#"+table+" #"+act);
    });
  }
  function del_row_lokal(tr){
    $("#"+tr).remove();
  }
  
  function hitung(k){
    var qty = $("#qty_"+k).val() * 1;
    var price = $("#price_"+k).val();
    price = price.replace("Rp ", "");
    
    while(price.indexOf(".") >= 0){
      price = price.replace(".", "");
    }
    price = price * 1;
    var discount = $("#discount_"+k).val() * 1;
    
    var jumlah = price * qty;
    
    var potongan = jumlah * discount / 100;
    
    var total = jumlah - potongan;
    
    $("#total_"+k).text("Rp " + get_dot(total));
    total_all();
  }
  function total_all(){
    var no = $("#nomor_flag").val() * 1;
//    console.log(no);
    var total_utama = 0;
    for( i = 1; i <= no ; i++){
      var price_satuan = $("#total_"+i).text();
//      console.log(price_satuan);
      price_satuan = price_satuan.replace("Rp ", "");
      while(price_satuan.indexOf(".") >= 0){
        price_satuan = price_satuan.replace(".", "");
      }
      price_satuan = price_satuan * 1;
//      console.log(price_satuan);
      total_utama = total_utama + price_satuan;
//      console.log(total_utama);
    }
    $("#total_utama").text("Rp " + get_dot(total_utama));
  }
  total_all();
</script>